home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 76 / XENIATGM66.iso / Indiana Jones / Indiana Jones.exe / RESOURCE / PREVIEW.GOB / cog_riv_wolflanding.cog < prev    next >
Text File  |  1999-11-15  |  12KB  |  524 lines

  1. # Jones 3D Cog Script
  2. #
  3. # olv_wolflanding.cog   
  4. #
  5. # [SCHOLL]
  6. #
  7. # (C) 1999 LucasArts Entertainment Company LLC. All Rights Reserved
  8. #
  9. # ========================================================================================
  10. symbols
  11.  
  12. message entered
  13. message    startup
  14. message    aievent
  15. message    arrivedwpnt
  16. message timer
  17.  
  18. thing    t_Wolf
  19. thing    t_Indy        local
  20.  
  21. int        n_eventType        local
  22. int        n_CrntAIMode     local
  23. int        n_OldAIMode     local
  24. int        n_Waypoint        local
  25. flex    f_DistToIndy    local 
  26. int        n_TimerID        local 
  27. flex    f_FleeTime        local
  28.  
  29. int        b_OKToStopFlee=0         local
  30. int        b_AttackOnStopFlee=0     local
  31. int        n_idx                    local
  32. int        b_WpntsActive=0            local
  33. int        n_FleeDir                local
  34.  
  35. vector    v_IndyPos        local
  36. vector    v_WolfPos        local
  37. vector    v_Temp            local
  38.  
  39.  
  40.  
  41. # ===========================FLEE WAYPOINTS================================================
  42. int            NUM_FLEE_WAYPOINTS=27            local
  43. thing        t_Waypoint00
  44. thing        t_Waypoint01
  45. thing        t_Waypoint02
  46. thing        t_Waypoint03
  47. thing        t_Waypoint04
  48. thing        t_Waypoint05
  49. thing        t_Waypoint06
  50. thing        t_Waypoint07
  51. thing        t_Waypoint08
  52. thing        t_Waypoint09
  53. thing        t_Waypoint10
  54. thing        t_Waypoint11
  55. thing        t_Waypoint12
  56. thing        t_Waypoint13
  57. thing        t_Waypoint14
  58. thing        t_Waypoint15
  59. thing        t_Waypoint16
  60. thing        t_Waypoint17
  61. thing        t_Waypoint18
  62. thing        t_Waypoint19
  63. thing        t_Waypoint20
  64. thing        t_Waypoint21
  65. thing        t_Waypoint22
  66. thing        t_Waypoint23
  67. thing        t_Waypoint24
  68. thing        t_Waypoint25
  69. thing        t_Waypoint26
  70.  
  71.  
  72. # ===========================SECTORS================================================
  73.  
  74. int            NUM_AUTO_FLEE_SECTORS=1     local
  75. sector        s_AutoFlee00            mask=0x5 # need entered messages from wolf
  76.  
  77. int            NUM_ACTIVATE_WPNT_SECTORS=2 local
  78. sector        s_ActivateWpnts00
  79. sector        s_ActivateWpnts01
  80.  
  81. int            NUM_DEACTIVATE_WPNT_SECTORS=1 local
  82. sector        s_DeactivateWpnts00
  83.  
  84.  
  85. # ===========================MISC CONSTANTS================================================
  86.  
  87. flex    MIN_FLEE_DISTANCE=2.0            local # distance wolf wants to be from Indy before stopping fleeing
  88. flex    MIN_FLEE_RESTART_DISTANCE=1.0            local # distance wolf wants to be from Indy before stopping fleeing
  89. flex    MAX_FLEEATTACK_DISTANCE=1.0            local # 
  90. flex    MIN_FLEE_TIME=4.0                local 
  91. flex    VARIABLE_FLEE_TIME=3.0            local
  92.  
  93. int        TIMER_ID_OKAY_TO_STOP_FLEE=0    local
  94. int        TIMER_ID_START_FLEE=1            local
  95. int        TIMER_ID_ATTACK=2            local
  96.  
  97. # ===========================SUBROUTINES================================================
  98.  
  99. flex    SetDistToIndy            local
  100. flex    ActivateWaypoints        local
  101. flex    DeactivateWaypoints        local
  102. flex    RankWaypointsForFlee     local
  103. flex    RankWaypointsForFleeToSouth local
  104. flex     RankWaypointsForFleeToNorth    local
  105. flex    ResetWaypointRanks        local
  106.  
  107. end
  108. # ========================================================================================
  109.  
  110. code
  111. startup:
  112.     t_Indy=GetLocalPlayerThing();
  113.  
  114.     call ActivateWaypoints;
  115.     return;
  116.  
  117. # ========================================================================================
  118. entered:
  119.     if (GetSourceRef() == t_Indy)
  120.     {
  121.         for (n_idx = 0; n_idx < NUM_ACTIVATE_WPNT_SECTORS; n_idx = n_idx + 1)
  122.         {
  123.             if (GetSenderRef() == s_ActivateWpnts00[n_idx])
  124.             {
  125.                 call ActivateWaypoints;
  126.             }
  127.         }
  128.         for (n_idx = 0; n_idx < NUM_DEACTIVATE_WPNT_SECTORS; n_idx = n_idx + 1)
  129.         {
  130.             if (GetSenderRef() == s_DeactivateWpnts00[n_idx])
  131.             {
  132.                 call DeactivateWaypoints;
  133.             }
  134.         }
  135.     }
  136.     else if (GetSourceRef() == t_Wolf)
  137.     {
  138.         for (n_idx = 0; n_idx < NUM_AUTO_FLEE_SECTORS; n_idx = n_idx + 1)
  139.         {
  140.             if (GetSenderRef() == s_AutoFlee00[n_idx])
  141.             {
  142. //                DebugPrint("Wolf auto fleeing");
  143.                 AIFlee(t_Wolf, t_Indy);
  144.             }
  145.         }
  146.     }
  147.  
  148.     return;
  149.  
  150. # ========================================================================================
  151. aievent:
  152.     n_eventType        = GetParam(0);
  153.     n_CrntAIMode    = GetParam(1);
  154.     n_OldAIMode        = GetParam(2);    // only valid for certain n_eventType values
  155.  
  156.     if (n_eventType == 0x100)        // SITHAI_EVENTMODECHANGED
  157.     {
  158.         // if changing to flee mode
  159.         // turn on waypoints
  160.         if ( !BITTEST(n_OldAIMode, 0x800) && BITTEST(n_CrntAIMode, 0x800) )
  161.         {
  162. //            DebugPrint("Entering flee mode");
  163.             AISetSubMode(t_Wolf, 0x8000); // SITHAI_SUBMODECONTINUOUSWPNTMOTION
  164.             f_FleeTime = (MIN_FLEE_TIME + (Rand() * VARIABLE_FLEE_TIME));
  165. //            DebugFlex( f_FleeTime, "Flee time");
  166.             SetTimerEx(f_FleeTime , TIMER_ID_OKAY_TO_STOP_FLEE, 0, 0 );
  167.             b_OKToStopFlee = 0;
  168.             call RankWaypointsForFlee;
  169.         }
  170.         // if exiting flee mode
  171.         // turn off waypoints
  172.         else if ( BITTEST(n_OldAIMode, 0x800) && !BITTEST(n_CrntAIMode, 0x800) )
  173.         {
  174.             call SetDistToIndy;
  175.         
  176.             if (b_AttackOnStopFlee)
  177.             {
  178.                 SetTimerEx(0.01 , TIMER_ID_ATTACK, 0, 0);
  179.                 b_AttackOnStopFlee = 0;
  180.                 AIClearSubMode(t_Wolf, 0x8000); // SITHAI_SUBMODECONTINUOUSWPNTMOTION
  181.                 call ResetWaypointRanks;
  182.             }
  183.             // Consider restarting fleeing if Indy too close
  184.             else if (f_DistToIndy < MIN_FLEE_RESTART_DISTANCE)
  185.             {
  186. //                DebugFlex(f_DistToIndy, "Wolf restarting fleeing due to distance");
  187.                 // Restart using timer to avoid nested mode changes
  188.                 SetTimerEx(0.01 , TIMER_ID_START_FLEE, 0, 0 );
  189.             }
  190.             else
  191.             {
  192.                 AIClearSubMode(t_Wolf, 0x8000); // SITHAI_SUBMODECONTINUOUSWPNTMOTION
  193.                 call ResetWaypointRanks;
  194. //                DebugPrint("Exiting flee mode");
  195.             }
  196.         }
  197.     }
  198.  
  199. return;
  200.  
  201. # ========================================================================================
  202. timer:
  203.     t_Indy = GetLocalPlayerThing();
  204.  
  205.     n_TimerID = GetSenderID();
  206.     if (n_TimerID == TIMER_ID_OKAY_TO_STOP_FLEE)
  207.     {
  208.         b_OKToStopFlee = 1;
  209.     }
  210.     else if (n_TimerID == TIMER_ID_START_FLEE)
  211.     {
  212.         call RankWaypointsForFlee;
  213.         AIFlee(t_Wolf, t_Indy);
  214.     }
  215.     else if (n_TimerID == TIMER_ID_ATTACK)
  216.     {
  217.         AISetFireTarget(t_Wolf, t_Indy);
  218.     }
  219.  
  220.  
  221.     return;
  222.  
  223.  
  224. # ========================================================================================
  225. arrivedwpnt:
  226.     n_Waypoint = GetParam(0);
  227.  
  228.     call SetDistToIndy;
  229.  
  230.     if ( b_OKToStopFlee 
  231.          && (f_DistToIndy > MIN_FLEE_DISTANCE)
  232.          && BITTEST(AIGetMode(t_Wolf), 0x800) // fleeing
  233.          && (RandBetween(0,100) < 90)
  234.          )
  235.     {
  236. //        DebugFlex(f_DistToIndy, "Wolf stopping fleeing due to distance");
  237.         // StopThing before StopFlee so wolf will turn to face indy
  238.         StopThing(t_Wolf);
  239.         AIStopFlee(t_Wolf);
  240.     }
  241.     else if ( b_OKToStopFlee 
  242.          && (f_DistToIndy < MAX_FLEEATTACK_DISTANCE)
  243.          && BITTEST(AIGetMode(t_Wolf), 0x800) // fleeing
  244.          && (RandBetween(0,100) < 30)
  245.          )
  246.     {
  247. //        DebugFlex(f_DistToIndy, "Wolf stopping fleeing. Surprise attack");
  248.         b_AttackOnStopFlee = 1;
  249.         AIStopFlee(t_Wolf);
  250.     }
  251.     else if ( (n_FleeDir == -1)
  252.               && BITTEST(AIGetMode(t_Wolf), 0x800) // fleeing
  253.               )
  254.     {
  255.         // fleeing south
  256.         if (n_Waypoint <=2)
  257.         {
  258.             if (f_DistToIndy > MIN_FLEE_RESTART_DISTANCE)
  259.             {
  260.                 // StopThing before StopFlee so wolf will turn to face indy
  261. //                DebugPrint("Wolf Reached Flee Waypoint and Stopped.");
  262.                 StopThing(t_Wolf);
  263.                 AIStopFlee(t_Wolf);
  264.             }
  265.             else
  266.             {
  267. //                DebugFlex(f_DistToIndy, "Wolf Restarting fleeing.");
  268.                 call RankWaypointsForFlee;
  269.             }
  270.         }
  271.     }
  272.     else if ( (n_FleeDir == 1)
  273.               && BITTEST(AIGetMode(t_Wolf), 0x800) // fleeing
  274.               )
  275.     {
  276.         // fleeing south
  277.         if (n_Waypoint >=23)
  278.         {
  279.             if (f_DistToIndy > MIN_FLEE_RESTART_DISTANCE)
  280.             {
  281.                 // StopThing before StopFlee so wolf will turn to face indy
  282. //                DebugPrint("Wolf Reached Flee Waypoint and Stopped.");
  283.                 StopThing(t_Wolf);
  284.                 AIStopFlee(t_Wolf);
  285.             }
  286.             else
  287.             {
  288. //                DebugFlex(f_DistToIndy, "Wolf Restarting fleeing.");
  289.                 call RankWaypointsForFlee;
  290.             }
  291.         }
  292.     }
  293.  
  294.     return;
  295.  
  296. # ========================================================================================
  297. SetDistToIndy:
  298.     v_IndyPos = GetThingPos(t_Indy);
  299.     v_WolfPos = GetThingPos(t_Wolf);
  300.  
  301.     f_DistToIndy = VectorDist(v_IndyPos, v_WolfPos);
  302.  
  303.     return;
  304.  
  305. # ========================================================================================
  306. ActivateWaypoints:
  307.     if (b_WpntsActive)
  308.     {
  309.         return;
  310.     }
  311.  
  312. //    DebugPrint("ACTIVATING WAYPOINTS FOR WOLF IN LANDING AREA");
  313.     b_WpntsActive = 1;
  314.     AISetInstinctWpntMode(t_Wolf);
  315.  
  316.     for ( n_idx = 0; n_idx < NUM_FLEE_WAYPOINTS; n_idx = n_idx + 1 )
  317.     {
  318.         AISetWpnt(t_Waypoint00[n_idx], n_idx);
  319.     }
  320.  
  321.     AIConnectWpnts(0, 1);
  322.     AIConnectWpnts(0, 4);
  323.     AIConnectWpnts(0, 5);
  324.     AIConnectWpnts(1, 2);
  325.     AIConnectWpnts(1, 5);
  326.     AIConnectWpnts(1, 6);
  327.     AIConnectWpnts(2, 3);
  328.     AIConnectWpnts(2, 6);
  329.     AIConnectWpnts(3, 6);
  330.     AIConnectWpnts(3, 7);
  331.     AIConnectWpnts(4, 5);
  332.     AIConnectWpnts(4, 8);
  333.     AIConnectWpnts(5, 6);
  334. //    AIConnectWpnts(5, 8);
  335. //    AIConnectWpnts(5, 9);
  336.     AIConnectWpnts(6, 7);
  337. //    AIConnectWpnts(6, 8);
  338. //    AIConnectWpnts(6, 9);
  339. //    AIConnectWpnts(7, 8);
  340.     AIConnectWpnts(7, 9);
  341.     AIConnectWpnts(8, 9);
  342.     AIConnectWpnts(8, 11);
  343.     AIConnectWpnts(8, 12);
  344.     AIConnectWpnts(9, 12);
  345.     AIConnectWpnts(10, 11);
  346.     AIConnectWpnts(10, 13);
  347.     AIConnectWpnts(10, 14);
  348.     AIConnectWpnts(11, 12);
  349.     AIConnectWpnts(11, 14);
  350.     AIConnectWpnts(12, 14);
  351.     AIConnectWpnts(12, 16);
  352.     AIConnectWpnts(12, 19);
  353.     AIConnectWpnts(13, 14);
  354.     AIConnectWpnts(13, 15);
  355.     AIConnectWpnts(13, 16);
  356.     AIConnectWpnts(14, 15);
  357.     AIConnectWpnts(14, 16);
  358.     AIConnectWpnts(15, 16);
  359.     AIConnectWpnts(15, 17);
  360.     AIConnectWpnts(15, 18);
  361.     AIConnectWpnts(16, 17);
  362.     AIConnectWpnts(16, 18);
  363.     AIConnectWpnts(17, 18);
  364.     AIConnectWpnts(17, 21);
  365.     AIConnectWpnts(17, 23);
  366.     AIConnectWpnts(18, 19);
  367.     AIConnectWpnts(18, 20);
  368.     AIConnectWpnts(18, 21);
  369.     AIConnectWpnts(19, 20);
  370.     AIConnectWpnts(20, 21);
  371.     AIConnectWpnts(20, 22);
  372.     AIConnectWpnts(21, 22);
  373.     AIConnectWpnts(21, 23);
  374.     AIConnectWpnts(21, 24);
  375.     AIConnectWpnts(21, 25);
  376.     AIConnectWpnts(21, 26);
  377.     AIConnectWpnts(22, 25);
  378.     AIConnectWpnts(23, 24);
  379.     AIConnectWpnts(24, 26);
  380.     AIConnectWpnts(25, 26);
  381.  
  382.     return;
  383.  
  384. # ========================================================================================
  385. DeactivateWaypoints:
  386.     if (!b_WpntsActive)
  387.     {
  388.         return;
  389.     }
  390.  
  391. //    DebugPrint("DEACTIVATING WAYPOINTS FOR WOLF LANDING");
  392.     b_WpntsActive = 0;
  393.     AIClearInstinctWpntMode(t_Wolf);
  394.     StopThing(t_Wolf);
  395.  
  396.     return;
  397.  
  398.  
  399. # ========================================================================================
  400. RankWaypointsForFlee:
  401.     v_IndyPos = GetThingPos(t_Indy);
  402.     v_Temp = GetThingPos(t_Waypoint10);
  403.  
  404.     if (VectorY(v_IndyPos) > VectorY(v_Temp))
  405.     {
  406.         call RankWaypointsForFleeToSouth;
  407.     }
  408.     else
  409.     {
  410.         call RankWaypointsForFleeToNorth;
  411.     }
  412.  
  413.     return;
  414.  
  415. # ========================================================================================
  416. RankWaypointsForFleeToSouth:
  417.     
  418. //    DebugPrint("Rank waypoints for Flee To South");
  419.     n_FleeDir = -1;
  420.  
  421.     AISetWpntRank(0, 135);
  422.     AISetWpntRank(1, 135);
  423.     AISetWpntRank(2, 135);
  424.     AISetWpntRank(3, 135);
  425.  
  426.     AISetWpntRank(4, 120);
  427.     AISetWpntRank(5, 120);
  428.     AISetWpntRank(6, 120);
  429.     AISetWpntRank(7, 120);
  430.  
  431.     AISetWpntRank(8, 105);
  432.     AISetWpntRank(9, 105);
  433.  
  434.     AISetWpntRank(10, 90);
  435.     AISetWpntRank(11, 90);
  436.     AISetWpntRank(12, 90);
  437.  
  438.     AISetWpntRank(13, 75);
  439.     AISetWpntRank(14, 75);
  440.  
  441.     AISetWpntRank(15, 60);
  442.     AISetWpntRank(16, 60);
  443.  
  444.     AISetWpntRank(17, 45);
  445.     AISetWpntRank(18, 45);
  446.     AISetWpntRank(19, 45);
  447.  
  448.     AISetWpntRank(20, 30);
  449.  
  450.     AISetWpntRank(21, 15);
  451.     AISetWpntRank(22, 15);
  452.     AISetWpntRank(23, 15);
  453.  
  454.     AISetWpntRank(24, 0);
  455.     AISetWpntRank(25, 0);
  456.     AISetWpntRank(26, 0);
  457.  
  458.  
  459.     return;
  460.  
  461. RankWaypointsForFleeToNorth:
  462.     
  463. //    DebugPrint("Rank waypoints for Flee To North");
  464.     n_FleeDir = 1;
  465.  
  466.     AISetWpntRank(0, 0);
  467.     AISetWpntRank(1, 0);
  468.     AISetWpntRank(2, 0);
  469.     AISetWpntRank(3, 0);
  470.  
  471.     AISetWpntRank(4, 15);
  472.     AISetWpntRank(5, 15);
  473.     AISetWpntRank(6, 15);
  474.     AISetWpntRank(7, 15);
  475.  
  476.     AISetWpntRank(8, 30);
  477.     AISetWpntRank(9, 30);
  478.  
  479.     AISetWpntRank(10, 45);
  480.     AISetWpntRank(11, 45);
  481.     AISetWpntRank(12, 45);
  482.  
  483.     AISetWpntRank(13, 60);
  484.     AISetWpntRank(14, 60);
  485.  
  486.     AISetWpntRank(15, 75);
  487.     AISetWpntRank(16, 75);
  488.  
  489.     AISetWpntRank(17, 90);
  490.     AISetWpntRank(18, 90);
  491.     AISetWpntRank(19, 90);
  492.  
  493.     AISetWpntRank(20, 105);
  494.  
  495.     AISetWpntRank(21, 120);
  496.     AISetWpntRank(22, 120);
  497.     AISetWpntRank(23, 120);
  498.  
  499.     AISetWpntRank(24, 135);
  500.     AISetWpntRank(25, 135);
  501.     AISetWpntRank(26, 135);
  502.  
  503.  
  504.     return;
  505.  
  506. # ========================================================================================
  507. ResetWaypointRanks:
  508.  
  509. //    DebugPrint("Reset waypoint ranks");
  510.  
  511.     n_FleeDir = 0;
  512.     for ( n_idx = 0; n_idx < NUM_FLEE_WAYPOINTS; n_idx = n_idx + 1 )
  513.     {
  514.         AISetWpntRank(n_idx, 0);
  515.     }
  516.  
  517.     return;
  518.  
  519.  
  520.  
  521.  
  522. end
  523.  
  524.